package com.ay272.ssh2.meal;

import javax.mail.*;
import java.util.Properties;

/**
 * Created by java on 2016/5/20.
 */
//收邮件
public class shoujian  {
    public static void main(String[] args) throws Exception{


        Properties pop = new Properties();
        pop.put("mail.imap.ssl.enable","true");
    Session session = Session.getDefaultInstance(pop,null);
    URLName urln = new URLName("imap","imap.qq.com",993,"INBOX",
            "asdasdbutvich@foxmail.com","wpkbiesihasrgagi");
    Store store = session.getStore(urln);
        store.connect();
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message[] messages = folder.getMessages();
        System.out.println("邮件个数"+folder.getMessageCount());
        System.out.println("未读"+folder.getUnreadMessageCount());
        System.out.println("新邮件个数"+folder.getNewMessageCount());

        for (Message m:messages
             ) {
            System.out.println(m.getSubject());
            System.out.println(m.getContent());

        }
        System.out.println("读取完毕");
    }
}
